package com.bruce.testxlog;

import android.app.Application;
import android.content.Context;
import android.os.Environment;

import com.elvishew.xlog.LogConfiguration;
import com.elvishew.xlog.LogLevel;
import com.elvishew.xlog.XLog;
import com.elvishew.xlog.printer.AndroidPrinter;
import com.elvishew.xlog.printer.ConsolePrinter;
import com.elvishew.xlog.printer.Printer;
import com.elvishew.xlog.printer.file.FilePrinter;
import com.elvishew.xlog.printer.file.naming.DateFileNameGenerator;

import timber.log.Timber;

/**
 * @author:
 * @project: TestXLog
 * @package: com.bruce.testxlog
 * @description: https://www.jianshu.com/p/1769d8aa1783
 * @date: 2020/4/13
 * @time: 15:15
 */
public class XLogApp extends Application {

    private static XLogApp instance;
    private static Context mContext;
    String appDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Log测试/";

    public static Context getContext() {
        return mContext;
    }

    public static XLogApp getInstance() {
        if (null == instance) {
            instance = new XLogApp();
        }
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mContext=getApplicationContext();

        Timber.plant(new DebugLoggerTree());

        //https://www.jianshu.com/p/1769d8aa1783
        LogConfiguration configuration = new LogConfiguration.Builder()
//                .logLevel(Common.Constance.openAllLog ? LogLevel.ALL : LogLevel.NONE)
                .tag("L-WL")
                .b()
                .build();

        Printer androidPrinter =  new AndroidPrinter();
        Printer consolePrinter =  new ConsolePrinter();
        Printer filePrinter = new FilePrinter
//                .Builder(appDir)
                .Builder(FileUtils.DIR_LOG) ///xLog测试
                .fileNameGenerator(new DateFileNameGenerator())
                .build();

        XLog.init(configuration, androidPrinter, consolePrinter, filePrinter);
    }
}
